<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型链继承</title>
</head>

<body>

</body>

</html>
<script>
    // **原型链继承**——易于实现，不能传参
    // 子类可以重写父类上方法
    // 父类中私有的或者公有的属性和方法, 最后都会变成子类公有的属性和方法


    //父
    function Person(name){//给构造函数添加了参数
        this.name = name;
        this.sum = function(){
            alert(this.name)
        }
    }
    Person.prototype.age = 10;//给构造函数添加了原型属性


    //父类型
    function Animation(name,age,sex){
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    Person.prototype.sayHi = function(){
        console.log('大家好，我是'+this.name);
    }

    //子类型
    function Student(){
        this.score = 100
    }

    Student.prototype = new Person()
    Student.prototype.constructor = Student;

    var s1 = new Person();
    s1.sayHi()  //大家好我是undefined
    console.log(s1.name);//undefined
    console.log(s1.age);//undefined
    console.log(s1.constructor);//Student


</script>